package com.barks.learning.base.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author chenw-i
 * @version 1.0.0
 * @ClassName Filter.java
 * @Description TODO
 * @createTime 2020年07月11日 18:51:00
 */
@Component
// Filter 直接使用Component就可以，interceptor是不可以的需要在config中手动加才行
public class CustomFilter implements Filter {
    private Logger logger = LoggerFactory.getLogger(CustomFilter.class);

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        logger.info("CustomFilter => doFilter before");
        filterChain.doFilter(servletRequest,servletResponse);
        logger.info("CustomFilter => doFilter after");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        logger.info("CustomFilter => init");
    }

    @Override
    public void destroy() {
        logger.info("CustomFilter => destroy");
    }
}
